﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AzureBlob
{
    /// <summary>
    /// Interaction logic for AccountSettingsDialog.xaml
    /// </summary>
    public partial class AccountSettingsDialog : Window
    {
        public AccountSettingsDialog(bool newAccount)
        {
            InitializeComponent();
            accountNameTextBox.IsEnabled = newAccount;
            OkBtn.IsEnabled = ValidateTextBox();
        }

        public string AccountName
        {
            get
            {
                return accountNameTextBox.Text;
            }
            set
            {
                accountNameTextBox.Text = value;
            }
        }

        public string AccountKey
        {
            get
            {
                return accountKeyTextBox.Text;
            }
            set
            {
                accountKeyTextBox.Text = value;
            }
        }

        public string CDN
        {
            get
            {
                return CDNTextBox.Text.Trim();
            }
            set
            {
                CDNTextBox.Text = value;
            }
        }

        private void OkBtn_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            OkBtn.IsEnabled = ValidateTextBox();
        }

        private bool ValidateTextBox()
        {
            if (CDNTextBox.Text.StartsWith("http://"))
                CDNTextBox.Text = CDNTextBox.Text.Substring(7);

            if (accountNameTextBox.Text.Trim().Length == 0)
                return false;
            if (accountKeyTextBox.Text.Trim().Length == 0)
                return false;
            
            return true;
        }
    }
}
